/ Assembly List / LJCDBDataAccess / DbDataAccess / LoadClientSql

Namespace - LJCDBDataAccess


Returns

The result XML message.

Syntax

C#
private DbResult LoadClientSql()

Executes a "Load" client SQL statement. (E)

Remarks

This method is called from the Execute() method if the DbRequest.QueryType is "LoadSql".

Example

C#
// Selects multiple records with an SQL statement.
private static Persons LoadClientSql(DbDataAccess dbDataAccess
  , DbColumns dataDefinition)
{
  Person retValue = null;

  StringBuilder builder = new StringBuilder(64);
  builder.AppendLine("select * from PersonTest");
  string sql = builder.ToString();

  DbColumns dataColumns = null;
  bool isColumnModifications = true;
  if (isColumnModifications)
  {
    // Create the list of included columns.
    // This list should include the database assigned columns.
    List<string> columnNames = new List<string>();
    foreach (DbColumn column in dataDefinition)
    {
      columnNames.Add(column.ColumnName);
    }

    // Create a Data Columns object with the included data definitions
    // and values from the data record.
    dataColumns = DbCommon.QueryColumns(columnNames, dataDefinition);
  }
    
  DbRequest dbRequest = new DbRequest()
  {
    ClientSql = sql
    Columns = dataColumns,
    QueryType = QueryType.LoadSQL.ToString(),
    TableName = "PersonTest",
  };
  DbResult dbResult = dbDataAccess.Execute(dbRequest);
    
  if (dbResult != null)
  {
    string sqlStatement = dbResult.ExecutedSql;
    if (dbResult.DbRecords != null && dbResult.DbRecords.Count > 0)
    {
      retValue = new Persons();
      foreach (DbValues dbValues in dbResult.DbRecords)
      {
        Person person = new Person();
        DbCommon.SetObjectValues(dbValues, retValue);
        retValue.Add(person);
      }
    }
    return retValue;
  }
}